<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/6/22 0022
 * Time: 22:25
 */

namespace Home\Controller;

use Think\Controller;

class XwController extends ComController
{
    public function index()
    {
        $news = M("news");
// 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
        $p = empty($_GET['p']) ? 0 : $_GET['p'];
        $list = $news->order('addtime')->page($p, 1)->select();
        $this->assign('list', $list);// 赋值数据集
        $count = $news->count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count, 1);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfig('prev', '上一页');
        $Page->setConfig('next', '下一页');
        $show = $Page->show();// 分页显示输出
        $this->assign('page', $show);// 赋值分页输出
        $this->display(); // 输出模板
    }

    public function xq()
    {
        $id = I("get.id");
        $news = M("news");
        $ret = $news->where("id=$id")->find();
        $num = empty($ret['num']) ? 0 : $ret['num'];
        $data['num'] = $num + 1;
        $news->where("id=$id")->save($data);
        $this->assign("ret", $ret);
        $this->display();
    }
}